package lar.system.sound;

import java.util.TreeSet;
import java.util.Vector;

import lar.system.engine.MainProgram;
import lar.system.R;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;

public class Sound 
{
	private static Vector<MediaPlayer> oneTimeSounds = new Vector<MediaPlayer>();
	private static boolean isSound = true;
	
	public static boolean isSound()
	{
		return isSound;
	}
	
	public static void disableSound()
	{
		isSound = false;
	}
	
	public static void enableSound()
	{
		isSound = true;
	}
	
	public static MediaPlayer playSound(int resource)
	{
		MediaPlayer mp = MediaPlayer.create(MainProgram.currentActivity, resource);
        if(mp == null) return null;
        oneTimeSounds.add(mp);
		mp.setOnCompletionListener(new OnCompletionListener() 
        {
            public void onCompletion(MediaPlayer mp) 
            {
                mp.release();
                oneTimeSounds.remove(mp);
            }

        });   
        if(!isSound) mp.setVolume(0, 0);
        mp.start();
        return mp;
	}
	
	public static MediaPlayer playSound(int resource, OnCompletionListener listener)
	{
		MediaPlayer mp = MediaPlayer.create(MainProgram.currentActivity, resource);
        if(mp == null) return null;
		mp.setOnCompletionListener(listener);
        if(!isSound) mp.setVolume(0, 0);
        mp.start();
        return mp;
	}
	
	

}
